import http from '@/utils/http'
import type { IUser } from '@/types'

//新增
export const userAdd = (payload: IUser) => {
    return http.post('/api/manage/user', payload)
}
//修改
export const userEdit = (payload: IUser) => {
    return http.put(`/api/manage/user`, payload)
}
//新增或修改
export const userEditOrAdd = (payload: IUser) => {
    if (payload.id) {
        return userEdit(payload)
    } else {
        return userAdd(payload)
    }
}
//删除
export const userDel = (id: number) => {
    return http.delete(`/api/manage/user/${id}`)
}
//查询
export const userList = () => {
    return http.get('/api/manage/user')
}
//根据id查询一个
export const userById = (id: number) => {
    return http.get(`/api/manage/user/${id}`)
}

export const userBatchDel = (delIds: number[]) => {
    const delTasks: Promise<IUser>[] = delIds.map(id => http.delete(`/api/manage/user/${id}`))
    return Promise.all(delTasks)
}